package com.ganbo.rabbitmq.ttl;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 过期队列和过期消息
 *
 * @Author: ganbo
 * @Date: 2020/12/8 20:03
 */

@Configuration
public class TtlConfig {

//    @Bean("ttlMessageQueue")
//    public Queue ttlMessageQueue() {
//        Map<String, Object> map = new HashMap();
//        map.put("x-message-ttl", 11000);    //队列中的消息未被消费11秒后过期
//        return new Queue("ttlMessageQueue", true, false, false, map);
//    }
//
//    @Bean("expireQueue")
//    public Queue expireQueue() {
//        Map<String, Object> map = new HashMap<String, Object>();
//        map.put("x-expire", 30000); // 队列30秒没有使用以后会被删除
//        return new Queue("GP_EXPIRE_QUEUE", true, false, false, map);
//    }
//
//
//    @Bean("ttlExchange")
//    public DirectExchange exchange() {
//        return new DirectExchange("GP_TTL_EXCHANGE", true, false, new HashMap<>());
//    }
//
//    @Bean
//    public Binding binding() {
//        return BindingBuilder.bind(ttlMessageQueue()).to(exchange()).with("gupao.ttl");
//    }
}
